<template>
  <div class="app-container tabs-content info-main">
    <el-form v-if="crud.status.cu> 0" ref="form" :inline="true" :model="form" :rules="rules" style="margin: 10px 0px 28px 0px;" size="small" label-width="150px">
      <div class="form-title">图片信息</div>
      <el-form-item prop="file1" style="width: 100%;margin-left: 144px;">
        <el-image
          v-if="fileList.length<=0"
          style="width: 370px; height: 226px;float: left"
          :src="form.image ?formatImage(form) : Avatar"
          :preview-src-list="[form.image ?formatImage(form) : Avatar]"
        />
        <el-upload
          ref="upload"
          drag
          action=""
          :limit="limit"
          :file-list="fileList"
          :auto-upload="true"
          :on-exceed="formHandleExceed"
          :on-change="formHandleChange"
          :on-remove="formHandleRemove"
          :before-upload="beforeUploadForm"
          :on-error="uploadError"
          :accept="acceptFile('img')"
          class="upload-demo"
          :headers="headers"
          :http-request="uploadFile"
          list-type="picture-card"
        >
          <i class="el-icon-upload" />
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        </el-upload>
        <div class="el-upload__tip"><span style="margin-left:44px;">上传文件只能是 png/jpg/jpeg/gif 格式！大小不能超过{{ formMaxSize }}M！</span></div>
      </el-form-item>
      <div class="form-title">基本信息</div>
      <el-form-item v-if="version==='test' || crud.form.projId || isView()" label="用途：" prop="useTo">
        <el-radio-group v-model="form.useTo" class="text-width">
          <el-radio disabled label="test">测试项目</el-radio>
          <el-radio disabled label="prod">正式项目</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-else-if="version==='prod'" label="用途：" prop="useTo">
        <el-radio-group v-model="form.useTo" class="text-width">
          <el-radio label="test">测试项目</el-radio>
          <el-radio label="prod">正式项目</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="工程号：" prop="constructionCode">
        <el-input v-model="form.constructionCode" class="text-width" :maxlength="100" :disabled="construction||isView()" />
      </el-form-item>
      <el-form-item label="项目编号：" prop="code">
        <el-input v-model="form.code" class="text-width" :maxlength="100" disabled />
      </el-form-item>
      <el-form-item label="主合同号：" prop="contractCode">
        <el-input v-model="form.contractCode" class="text-width" :maxlength="100" :disabled="contract||isView()" />
      </el-form-item>
      <el-form-item label="项目名称：" prop="code">
        <el-input v-model="form.name" class="text-width" :maxlength="100" disabled />
      </el-form-item>
      <el-form-item label="项目类型：" prop="type">
        <el-radio-group v-model="form.type" class="text-width" disabled>
          <el-radio v-for="item in dict.project_type" :key="item.id" :label="item.value">{{ item.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="所属行业：" prop="industry">
        <el-select v-model="form.industry" placeholder="请选择" class="text-width" :disabled="isView()">
          <el-option
            v-for="item in dict.project_industry"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="产能：" prop="capacity">
        <el-input v-model="form.capacity" class="text-width" :maxlength="100" :disabled="isView()" />
      </el-form-item>
      <el-form-item label="总建筑面积：" prop="overallFloorage">
        <el-input-number v-model="form.overallFloorage" class="text-width4" :controls="false" :precision="2" :min="0" :max="9999999" :maxlength="10" :disabled="isView()" /> ㎡
      </el-form-item>
      <el-form-item label="建筑高度：" prop="buildingHeight">
        <el-input-number v-model="form.buildingHeight" class="text-width4" :controls="false" :precision="2" :min="0" :max="9999999" :maxlength="10" :disabled="isView()" /> m
      </el-form-item>
      <el-form-item label="地区：" prop="area">
        <wlAddress ref="wlAdress" v-model="form.area" :is-foreign.sync="form.isForeign" class="my-wl-address text-width" type="default" :address.sync="form.area" :maxlength="200" :disabled="isView()" :nation-code="form.nationCode" />
      </el-form-item>
      <el-form-item label="地址：" prop="address">
        <el-input v-model="form.address" class="text-width" :disabled="isView()" />
      </el-form-item>
      <el-form-item label="项目简介：" prop="introductory">
        <el-input v-model="form.introductory" :rows="3" type="textarea" class="text-width" :maxlength="500" :disabled="isView()" />
      </el-form-item>
      <div class="form-title">参与方</div>
      <el-form-item label="主承接：" prop="deptId">
        <treeselect
          v-model="form.deptId"
          :disable-branch-nodes="true"
          class="text-width"
          disabled
          :options="depts"
          :load-options="loadDepts"
        />
      </el-form-item>
      <el-form-item label="配合公司：" prop="assistCompany">
        <treeselect
          ref="assist"
          v-model="assistCompanyIds"
          :disable-branch-nodes="true"
          disabled
          :multiple="true"
          :options="assistCompanys"
          :load-options="assistLoadDepts"
          class="text-width"
          :class="isView()?'treeColor':''"
          placeholder="请选择"
        />
      </el-form-item>
      <el-form-item label="委托单位：">
        <treeselect
          ref="constructionUnitId"
          v-model="form.constructionUnitId"
          :disabled="isView()"
          :disable-branch-nodes="true"
          :options="constructionUnits"
          :load-options="loadConstructionUnits"
          class="text-width"
          :class="crud.form.projId!==null||isView()?'treeColor':''"
          :placeholder="form.constructionUnit?form.constructionUnit:'请选择'"
        />
      </el-form-item>
      <el-form-item label="项目管理员：">
        <div class="text-width">{{ form.pjManagerName }}</div>
      </el-form-item>
      <el-form-item label="项目策划人：">
        <div class="text-width">{{ form.plannerName }}</div>
      </el-form-item>
      <el-form-item label="项目经理：" prop="managerDatas" class="star">
        <el-select
          v-model="managerDatas"
          v-defaultSelect="[managerDefaultSelect]"
          class="text-width"
          multiple
          placeholder="请选择"
          @remove-tag="deleteTag"
          @change="changeManager"
        >
          <el-option
            v-for="item in form.managers"
            v-show="item.enabled"
            :key="item.user_id"
            :label="item.nickName"
            :value="item.user_id"
            :disabled="managerDatas.some(data=> data === item.user_id)"
          />
        </el-select>
      </el-form-item>
      <div class="form-title">项目进度</div>
      <el-form-item label="项目阶段：" prop="stage">
        <el-select v-model="form.stage" clearable placeholder="请选择" class="text-width" :disabled="isView()">
          <el-option
            v-for="item in dict.stage"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="运行状态：" prop="runStatus">
        <el-select v-model="form.runStatus" clearable placeholder="请选择" class="text-width" :disabled="isView()">
          <el-option
            v-for="item in runStatusList"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="启动状态：" prop="startStatus">
        <div class="text-width">
          {{ formatStartStatus(form.startStatus,form.updateStatus) }}
          <el-tooltip slot="right" effect="dark" content="已启动子项数/总子项数" placement="top-start"><span>{{ startNumuber(form.projId) }}/{{ (!form.projectSubs)?0:(form.hasOwnProperty('projectSubs')&&form.projectSubs.some(data=> data.subNo === '9999'))?form.projectSubs.length-1:form.projectSubs.length }}</span></el-tooltip>
        </div>
      </el-form-item>
      <div class="form-title">软件技术</div>
      <el-form-item label="设计软件：" prop="softWare" class="star">
        <el-select v-model="softWareDatas" v-defaultSelect="[softWareDefaultSelect]" multiple placeholder="请选择" class="text-width" :disabled="isView()" @remove-tag="deleteSoftWare" @change="changeSoftWare">
          <el-option
            v-for="item in dict.software"
            :key="item.id"
            :label="item.label"
            :value="item.value"
            :disabled="(form.designSoftware&&form.designSoftware.includes(item.value))||item.currentIndex===item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="项目模板：" prop="template">
        <el-select v-model="form.template" placeholder="请选择" class="text-width" :disabled="isView()||(form.startStatus === 1||form.startStatus === 2)">
          <el-option
            v-for="item in template_file"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-if="checkPer(['admin','project:lookComos'])" label="comos软件状态：" prop="comosStatus">
        <div class="text-width">
          <el-switch v-model="form.comosStatus" :disabled="!checkPer(['admin','project:comos'])" :active-value="1" :inactive-value="0" />
        </div>
      </el-form-item>
      <el-form-item v-if="checkPer(['admin','project:lookComos'])" label="comos管理员：" prop="comosManager">
        <el-select v-model="form.comosManager" filterable :disabled="form.comosStatus===0 || !checkPer(['admin','project:comos'])" class="text-width" placeholder="请选择">
          <el-option
            v-for="item in comosOptions"
            :key="item.userId"
            :label="item.nickName"
            :value="item.userId"
          />
        </el-select>
      </el-form-item>
      <div class="dialog-footer" style="float:right;">
        <el-button v-if="isView()" type="button" @click="crud.cancelCU">关闭</el-button>
        <div v-else>
          <el-button @click="cancelEdit">取消</el-button>
          <el-button slot="reference" :loading="crud.status.cu === 2" type="primary" @click="save()">保存</el-button>
        </div>
      </div>
    </el-form>
    <div v-else>
      <ProjectInfoDetail
        :base-api="baseApi"
        :project-data="projectInfo"
        is-admin
        :form="form"
        :dict="dict"
        :permission="permission"
        :assist-company-ids="assistCompanyIds"
        :assist-companys="assistCompanys"
        :construction-units="constructionUnits"
        :depts="depts"
        :comos-options="comosOptions"
        :look-comos="lookComos"
        @doStart="start"
        @doUpdate="update"
      />
      <!-- <div class="projectInfo-info">
          <div class="form-title">基本信息</div>
          <el-row class="info-row">
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">用途：<div><span v-if="form.useTo==='test'">测试项目</span><span v-if="form.useTo==='prod'">正式项目</span></div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">工程号：<div>{{ form.constructionCode }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">项目编号：<div>{{ form.code }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">主合同号：<div>{{ form.contractCode }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">项目名称：<div>{{ form.name }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">项目类型：<div>{{ dict.label.project_type[form.type] }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">所属行业：<div>{{ dict.label.project_industry[form.industry] }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">产能：<div>{{ form.capacity }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">总建筑面积：<div>{{ form.overallFloorage }}㎡</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">建筑高度：<div>{{ form.buildingHeight }}m </div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">地区：<div style="margin-top: -10px;">
              <wlAddress v-show="form.area" ref="wlAdress" v-model="form.area" v-viewinput:address="true" :is-foreign.sync="form.isForeign" class="my-wl-address" type="default" :address.sync="form.area" disabled :nation-code="form.nationCode" />
            </div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">地址：<div>{{ form.address }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">项目简介：<div>{{ form.introductory }}</div> </el-col>
          </el-row>
          <div class="form-title">参与方</div>
          <el-row class="info-row">
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">主承接：<div style="margin-top: -10px;">
              <treeselect
                v-model="form.deptId"
                v-viewinput:treeselect="true"
                :disable-branch-nodes="true"
                disabled
                :options="depts"
                :load-options="loadDepts"
              />
            </div>
            </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">配合公司：<div style="margin-top: -9px">
              <treeselect
                v-show="assistCompanyIds.length>0"
                v-model="assistCompanyIds"
                v-viewinput:multtreeselect.notag="true"
                :disable-branch-nodes="true"
                disabled
                :multiple="true"
                :options="assistCompanys"
                :load-options="assistLoadDepts"
              />
            </div>
            </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">委托单位：<div style="margin-top: -9px">
              <treeselect
                v-show="form.constructionUnitId"
                v-model="form.constructionUnitId"
                v-viewinput:treeselect="true"
                :disable-branch-nodes="true"
                disabled
                :options="constructionUnits"
                :load-options="loadConstructionUnits"
              />
            </div>
            </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">项目管理员：<div>{{ form.pjManagerName }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">项目策划人：<div>{{ form.plannerName }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">项目经理：<div>{{ form.manager?formatManager(form.manager):'' }}</div> </el-col>
          </el-row>
          <div class="form-title">项目进度</div>
          <el-row class="info-row">
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">项目阶段：<div>{{ dict.label.stage[form.stage] }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">运行状态：<div>{{ form.runStatus?formatRunStatus( form.runStatus):'' }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">启动状态：<div style="margin-top: -8px">
              <el-tooltip slot="right" effect="dark" content="启动" placement="top-start">
                <el-popover
                  v-if="!form.hasOwnProperty('startStatus')||!(form.startStatus === 2)"
                  :ref="form.projId"
                  placement="top"
                  width="200"
                >
                  <p>确定启动吗？</p>
                  <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="$refs[form.projId].doClose()">取消</el-button>
                    <el-button type="primary" size="mini" @click="start(form.projId,form.projId)">确定</el-button>
                  </div>
                  <el-button slot="reference" v-permission="permission.start" :disabled="(!form.hasOwnProperty('delFlag')?true:form.delFlag)||form.startStatus === 1||form.startStatus === 2||(form.site&&form.site.siteId!==user.site.siteId)" style="margin: 0 3px 0 0;" class="filter-item" size="mini" type="primary" icon="el-icon-caret-right" />
                </el-popover>
              </el-tooltip>
              <el-tooltip slot="right" effect="dark" content="更新" placement="top-start">
                <el-popover
                  v-if="form.startStatus === 2"
                  :ref="form.projId"
                  placement="top"
                  width="200"
                >
                  <p>确定更新吗？</p>
                  <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="$refs[form.projId].doClose()">取消</el-button>
                    <el-button type="primary" size="mini" @click="update(form.projId,form.projId)">确定</el-button>
                  </div>
                  <el-button slot="reference" v-permission="permission.start" :disabled="(!form.hasOwnProperty('delFlag')?true:form.delFlag)||form.updateStatus === 1||form.updateStatus === 2" style="margin: 0 3px 0 0;" class="filter-item" size="mini" type="warning" icon="el-icon-caret-right" />
                </el-popover>
              </el-tooltip>
              <span v-show="!form.hasOwnProperty('startStatus')||(form.startStatus === 0||(form.startStatus === 2&&form.updateStatus === 0))">
                <svg-icon icon-class="noStart" />
              </span>
              <span v-show="form.startStatus===2 && form.updateStatus === 2">
                <svg-icon icon-class="success" />
              </span>
              <span v-show="form.startStatus === -1||(form.startStatus===2&&form.updateStatus === -1)">
                <svg-icon icon-class="exception" />
              </span>
              <span v-show="form.startStatus === 1||(form.startStatus===2&&form.updateStatus === 1)">
                <div style="display: inline-block;vertical-align: middle;">
                  <img :src="Starting" class="starting">
                </div>
              </span>
              <el-tooltip slot="right" effect="dark" content="已启动子项数/总子项数" placement="top-start"><span>{{ startNumuber(form.projId) }}/{{ (!form.projectSubs)?0:(form.hasOwnProperty('projectSubs')&&form.projectSubs.some(data=> data.subNo === '9999'))?form.projectSubs.length-1:form.projectSubs.length }}</span></el-tooltip>
            </div> </el-col>
          </el-row>
          <div class="form-title">软件技术</div>
          <el-row class="info-row">
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">设计软件：<div>{{ form.designSoftware?formatDesignSoftware(form.designSoftware):'' }}</div> </el-col>
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">项目模板：<div>{{ form.template }}</div> </el-col>
            <el-col v-if="checkPer(['admin','project:lookComos'])" :xs="24" :sm="24" :md="12" :lg="12" :xl="8">comos软件状态：<div>{{ form.comosStatus === 1 ? '启用':'禁用' }}</div> </el-col>
            <el-col v-if="checkPer(['admin','project:lookComos'])" :xs="24" :sm="24" :md="12" :lg="12" :xl="8">comos管理员：<div>{{ comosOptions.filter(item=> item.userId === form.comosManager)[0]?.nickName }}</div> </el-col>
          </el-row>
        </div>-->

      <div class="dialog-footer" style="height: 33px;">
        <div style="float: right;">
          <el-button v-if="!form.projId" v-permission="permission.add" :disabled="form.startStatus === 1||(form.startStatus===2&&form.updateStatus === 1)" size="mini" type="primary" @click="crud.toAdd">新增</el-button>
          <el-button v-if="!form.projId" v-permission="permission.add" :disabled="form.startStatus === 1||(form.startStatus===2&&form.updateStatus === 1)" size="mini" type="primary" @click="synchronousAllProjInfo">与OA同步</el-button>
          <el-button v-if="form.projId" v-permission="permission.edit" :disabled="form.startStatus === 1||(form.startStatus===2&&form.updateStatus === 1)" size="mini" type="primary" @click="crud.toEdit(form)">修改</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Avatar from '@/assets/images/architecture.jpg'
import { getToken } from '@/utils/auth'
import { mapGetters } from 'vuex'
import store from '@/store'
import CRUD, { presenter, header, form, crud } from '@brotherCrud/crud'
import WlAddress from '@brother/address/index.vue'
import Treeselect, { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { trimAllTab } from '@/utils'
import { validateFile } from '@/utils/validate'
import Starting from '@/assets/images/starting.gif'
import { getDepts, getDeptSuperior, getDeptSuperiorSelf } from '@/api/system/dept'
import { findDeptUsers } from '@/api/project/humanRes'
import crudProject, { start, projectStatus, doUpdateStatus, fetchAndSyncAllProjInfo } from '@/api/project/project'
import ProjectInfoDetail from '@brother/projectInfoDetail'
let designSoftware = []
let userManagers = []
// let externalReviewer = []
const defaultForm = { projId: null, useTo: '', code: null, name: null, type: null, manager: null, introductory: null, createBy: null, updateBy: null, createTime: null, updateTime: null, area: '', address: null, assistCompany: null, constructionUnitId: null, industry: null, overallFloorage: null, buildingHeight: null, designSoftware: [], template: null, isForeign: null, runStatus: null, stage: null, capacity: null, file: null, deptId: null, contractCode: null, constructionCode: null, site: {}, startStatus: null, updateStatus: null, projectSubs: [], pjManagerName: null, plannerName: null, deptName: null, managers: [], nationCode: '', delFlag: true, comosStatus: '', comosManager: '' }

export default {
  name: 'ProjectInfo',
  components: { WlAddress, Treeselect, ProjectInfoDetail },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['project_type', 'project_industry', 'software', 'Template_file', 'stage', 'Template_file'],
  cruds() {
    return CRUD({ title: '项目', url: 'api/project', query: { appModel: 'system', projCode: JSON.parse(localStorage.getItem('projectObject')).projCode, initId: JSON.parse(localStorage.getItem('projectObject')).initId }, idField: 'projId', sort: 'proj_id,desc', ColumnsSelectedShow: false, crudMethod: { ...crudProject }})
  },
  data() {
    const validateCode = (rule, value, callback) => {
      if (!value) {
        callback(new Error('项目编号不能为空'))
      } else if (!validateFile(value)) {
        callback(new Error('项目编号必须符合文件名命名规则'))
      } else if (value.indexOf('-') !== -1) {
        callback(new Error("项目编号不能含有  ' - '"))
      } else {
        this.form.code = trimAllTab(value, 'g')
        callback()
      }
    }
    const validateConstructionCode = (rule, value, callback) => {
      if (!value) {
        callback()
      } else if (!validateFile(value)) {
        callback(new Error('工程号必须符合文件名命名规则'))
      } else {
        this.form.constructionCode = trimAllTab(value, 'g')
        callback()
      }
    }
    return {
      show: false,
      Avatar: Avatar,
      headers: {
        'Authorization': getToken()
      },
      fileList: [], // 文件列表
      limit: 1,
      /* 上传文件大小*/
      formMaxSize: 10,
      uploadFormData: '', // 上传参数
      projectInfo: {}, // 项目信息
      version: '', // 区分测试版还是正式版
      projId: null,
      deptId: null,
      constructionUnitId: null,
      depts: [],
      constructionUnits: [],
      assistCompanys: [], // 配合公司
      assistCompanyIds: [], // 页面配合公司选中值
      softWareDatas: [], // 设计软件多选变量
      timer: '', // 接受定时器
      time: [], // 启动时间
      pageType: '', // 页面类型
      Starting: Starting, // 启动中图片
      softWareDefaultSelect: [], // 设计软件编辑时的默认值
      managerDefaultSelect: [], // 项目经理编辑时的默认值
      searchButtonName: '高级搜索',
      advancedSearch: false,
      template_file: [], // 模板列表
      managerDatas: [],
      construction: true, // 工程号是否有值
      contract: true, // 合同号是否有值
      runStatusList: [
        { label: '进行中', value: 1 },
        { label: '暂停', value: 2 },
        { label: '完成', value: 3 },
        { label: '废除', value: 4 }
      ], // 运行状态
      overallFloorageList: [
        { label: '0-5万平方米', id: 1, value: [0, 50000] },
        { label: '5-10万平方米', id: 2, value: [50000, 100000] },
        { label: '10-20万平方米', id: 3, value: [100000, 200000] },
        { label: '20-50万平方米', id: 4, value: [200000, 500000] },
        { label: '50万平方米以上', id: 5, value: [500000] }
      ], // 建筑面积
      permission: {
        add: ['admin', 'project:add'],
        edit: ['admin', 'project:edit'],
        del: ['admin', 'project:del'],
        download: ['admin', 'project:download'],
        start: ['admin', 'project:start'],
        comos: ['admin', 'project:comos']
      },
      rules: {
        useTo: [
          { required: true, message: '用途不能为空', trigger: 'change' }
        ],
        code: [
          { required: true, validator: validateCode, trigger: 'blur' },
          { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '项目名称不能为空', trigger: 'blur' },
          { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '项目类型不能为空', trigger: 'blur' }
        ],
        manager: [
          { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
        ],
        introductory: [
          { min: 0, max: 500, message: '长度在 0 到 500 个字符', trigger: 'blur' }
        ],
        area: [
          { required: true, message: '地区不能为空', trigger: 'blur' }
        ],
        industry: [
          { required: true, message: '所属行业不能为空', trigger: 'blur' }
        ],
        template: [
          { required: true, message: '模板不能为空', trigger: 'blur' }
        ],
        capacity: [
          { required: true, message: '产能不能为空', trigger: 'blur' },
          { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
        ],
        contractCode: [
          { min: 0, max: 100, message: '长度在 0 到 100 个字符', trigger: 'blur' }
        ],
        constructionCode: [
          { validator: validateConstructionCode, trigger: 'blur' },
          { min: 0, max: 100, message: '长度在 0 到 100 个字符', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'code', display_name: '项目编号' },
        { key: 'name', display_name: '项目名称' },
        { key: 'type', display_name: '项目类型' },
        { key: 'area', display_name: '地区' },
        { key: 'industry', display_name: '所属行业' },
        { key: 'constructionUnitId', display_name: '委托单位' },
        { key: 'overallFloorage', display_name: ' 项目总建筑面积' },
        { key: 'designSoftware', display_name: '设计软件' }
      ],
      comosOptions: []
    }
  },
  computed: {
    ...mapGetters([
      'user',
      'updateAvatarApi',
      'baseApi'
    ]),
    lookComos() {
      return this.checkPer(['admin', 'project:lookComos'])
    }

  },
  watch: {
    // 设计软件"PDMS"和“AutoCAD_Plant_3D”二选一
    'softWareDatas': {
      handler: function handler() {
        this.dict.software.map(item2 => {
          item2.currentIndex = ''
        })
        if (this.softWareDatas.length > 0) {
          this.softWareDatas.map(item => {
            this.dict.software.map(item2 => {
              if (item === '1') {
                item2.currentIndex = '4'
              }
              if (item === '4') {
                item2.currentIndex = '1'
              }
            })
          })
        }
        // 新增的值不能删除
        const softWareDefaultSelect = this.softWareDefaultSelect
        const a = softWareDefaultSelect.filter(item => !this.softWareDatas.includes(item))
        if (a.length > 0) {
          this.softWareDatas.push(...a)
        }
      }
    }
  },
  created() {
    this.getData()
  },
  mounted() {
    this.timesumming()
    this.startNumuber()
    this.getVersion()
  },
  beforeDestroy() {
    clearInterval(this.timer)
  },
  destroyed() {
    clearInterval(this.timer)
  },
  methods: {
    doClose() {
      console.log(222)
      this.$refs[this.form.projId].doClose()
    },
    // 获取值
    getData() {
      this.projectInfo = JSON.parse(localStorage.getItem('projectObject'))
      if (this.projectInfo.constructionCode) {
        this.construction = true
      } else {
        this.construction = false
      }
      if (this.projectInfo.contractCode) {
        this.contract = true
      } else {
        this.contract = false
      }
      Object.assign(this.form, {
        constructionCode: this.projectInfo.constructionCode, // 工程号
        contractCode: this.projectInfo.contractCode, // 合同号
        deptId: this.projectInfo.projDeptId, // 主承接
        code: this.projectInfo.projCode, // 项目编号
        type: this.projectInfo.projType, // 项目类型
        name: this.projectInfo.projName, // 项目名称
        projId: this.projectInfo.projId, // 项目Id
        file: this.projectInfo.file, // 图片
        startStatus: this.projectInfo.startStatus, // 启动状态
        updateStatus: this.projectInfo.updateStatus, // 更新状态
        introductory: this.projectInfo.introductory, // 项目简介
        useTo: this.projectInfo.useTo, // 用途
        industry: this.projectInfo.industry, // 所属行业
        overallFloorage: this.projectInfo.overallFloorage, // 总建筑面积
        buildingHeight: this.projectInfo.buildingHeight, // 建筑高度
        capacity: this.projectInfo.capacity, // 产能
        area: this.projectInfo.area, // 地区
        address: this.projectInfo.address, // 地址
        constructionUnitId: this.projectInfo.constructionUnitId, // 委托单位
        designSoftware: this.projectInfo.designSoftware, // designSoftware
        manager: this.projectInfo.manager, // 项目经理
        template: this.projectInfo.template, // 项目模板
        isForeign: this.projectInfo.isForeign, //
        runStatus: this.projectInfo.runStatus, // 运行状态
        stage: this.projectInfo.stage, // 项目阶段
        image: this.projectInfo.image, //
        site: this.projectInfo.site, // 站点
        projectSubs: this.projectInfo.projectSubs, // 子项
        pjManagerName: this.projectInfo.pjManagerName,
        plannerName: this.projectInfo.plannerName,
        deptName: this.projectInfo.deptName,
        managers: this.projectInfo.plannerList,
        assistCompany: this.projectInfo.assistCompany,
        comosStatus: this.projectInfo.comosStatus,
        comosManager: this.projectInfo.comosManager,
        delFlag: this.projectInfo.delFlag ? this.projectInfo.delFlag : false
      })
      if (this.projectInfo.projId) {
        this.getProjectstatus(this.projectInfo.projId)
      }
      if (this.projectInfo.area && JSON.parse(this.projectInfo.area)[0].code) {
        this.form.nationCode = JSON.parse(this.projectInfo.area)[0].code// 获取code
      }
      if (this.projectInfo.projDeptId) {
        this.getSelfSupDepts(this.projectInfo.projDeptId)
      } else {
        this.getDepts()
      }
      this.assistCompanyIds = []
      if (this.projectInfo.assistCompany && JSON.parse(this.projectInfo.assistCompany).length > 0) {
        this.assistCompanyIds = JSON.parse(this.projectInfo.assistCompany)
        this.getSupDepts(this.projectInfo.assistCompany, '2')
      } else {
        this.getAssist()
      }
      if (this.projectInfo.constructionUnitId) {
        this.getSupDepts(this.projectInfo.constructionUnitId, '1')// 委托单位
      } else {
        this.getUnitDepts()
      }
      findDeptUsers({ deptId: this.projectInfo.projDeptId, deptIds: this.projectInfo.assistCompany && JSON.parse(this.projectInfo.assistCompany) }).then(res => {
        this.comosOptions = res
      })
    },
    toggleShow() {
      this.show = !this.show
    },
    cropUploadSuccess(jsonData, field) {
      store.dispatch('GetInfo').then(() => {
      })
    },
    timesumming() {
      const _this = this
      clearInterval(_this.timer)
      this.timer = setInterval(() => {
        if ((this.form.hasOwnProperty('startStatus') && this.form.startStatus === 1) || (this.form.hasOwnProperty('updateStatus') && this.form.updateStatus === 1)) {
          if (this.form.projId) {
            this.getProjectstatus(this.form.projId)
          }
        }
      }, 1000)
    },
    /* 取得项目状态*/
    getProjectstatus(id) {
      const params = {
        id: id
      }
      projectStatus(params).then(data => {
        if (data) {
          this.form.startStatus = data.startStatus
          this.form.updateStatus = data.updateStatus
        }
      })
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh](crud) {
      return true
    },
    // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form, type) {
      this.pageType = ''
      if (!form.projId) {
        form.isForeign = false// 默认国内
        this.form.nationCode = ''
      } else {
        // 查看时
        if (type === 'view') {
          this.pageType = type
        }
        return true
      }
    },
    // 新增前将多选的值设置为空
    [CRUD.HOOK.beforeToAdd]() {
      this.fileList = []
      this.softWareDatas = []
      this.softWareDefaultSelect = []
      this.managerDefaultSelect = []
      designSoftware = []
      this.managerDatas = []
      userManagers = []
      Object.assign(this.form, {
        projId: this.projectInfo.projId, // 项目Id
        type: this.projectInfo.projType, // 项目类型
        constructionCode: this.projectInfo.constructionCode, // 工程号
        contractCode: this.projectInfo.contractCode, // 合同号
        deptId: this.projectInfo.projDeptId, // 主承接
        code: this.projectInfo.projCode, // 项目编号
        name: this.projectInfo.projName, // 项目名称
        pjManagerName: this.projectInfo.pjManagerName,
        plannerName: this.projectInfo.plannerName,
        useTo: this.projectInfo.useTo,
        deptName: this.projectInfo.deptName,
        managers: this.projectInfo.plannerList,
        delFlag: this.projectInfo.delFlag ? this.projectInfo.delFlag : false
      })
      const value = { label: this.projectInfo.deptName }
      this.addSelect(value)
      // 用途的默认值
      if (this.version === 'test' || this.crud.form.projId || this.isView()) {
        this.form.useTo = 'test'
      } else if (this.version === 'prod') {
        this.form.useTo = ''
      }
    },
    // 初始化编辑时候的设计软件
    [CRUD.HOOK.beforeToEdit](crud, form) {
      this.fileList = []
      this.getData()
      const value = { label: this.form.deptName }
      this.addSelect(value)
      this.softWareDatas = []
      designSoftware = []
      const softWareDefaultSelect = []
      const _this = this
      if (form.designSoftware) {
        const software = JSON.parse(form.designSoftware)
        if (software.length > 0) {
          software.forEach(function(item) {
            _this.softWareDatas.push(item.id)
            softWareDefaultSelect.push(item.id)
            const data = { id: item.id }
            designSoftware.push(data)
          })
        }
      }
      _this.softWareDefaultSelect = softWareDefaultSelect

      this.managerDatas = []
      userManagers = []
      const managerDefaultSelect = []
      if (form.manager) {
        const manager = JSON.parse(form.manager)
        manager.forEach(function(manager) {
          if (manager.enabled === 1) {
            _this.managerDatas.push(manager.user_id)
            managerDefaultSelect.push(manager.user_id)
          }
          const data = { user_id: manager.user_id, enabled: manager.enabled }
          userManagers.push(data)
        })
      }
      _this.managerDefaultSelect = managerDefaultSelect
    },
    // 验证前
    [CRUD.HOOK.beforeValidateCU](crud) {
      // 地址验证
      if (crud.form.area) {
        const a = JSON.parse(crud.form.area).some(item => {
          return item.code === ''
        })
        if (a) {
          crud.form.area = ''
        }
      }
    },
    // 提交前做的操作
    [CRUD.HOOK.afterValidateCU](crud) {
      crud.form.constructionUnit = ''
      if (this.softWareDatas.length === 0) {
        this.$message({
          message: '设计软件不能为空',
          type: 'warning'
        })
        return false
      }
      if (this.managerDatas.length === 0) {
        this.$message({
          message: '项目经理不能为空',
          type: 'warning'
        })
        return false
      }
      if (userManagers.length > 0) {
        crud.form.manager = JSON.stringify(userManagers)
      }
      if (designSoftware.length > 0) {
        crud.form.designSoftware = JSON.stringify(designSoftware)
      }
      if (this.assistCompanyIds.length > 0) {
        crud.form.assistCompany = JSON.stringify(this.assistCompanyIds)
      }
      return true
    },
    // 提交之后
    [CRUD.HOOK.afterSubmit]() {
      this.$store.state.tagsView.cachedViews.splice(this.$store.state.tagsView.cachedViews.indexOf('Project'), 1)
      if (this.crud.addData.code) {
        this.crud.query.projCode = this.crud.addData.code
      }
      this.crud.refresh()
      this.$emit('noticeRefresh')
    },
    // 刷新之后
    [CRUD.HOOK.afterRefresh]() {
      this.crud.data.map(item => {
        if (this.projectInfo.initId === item.initId) {
          this.$store.commit('app/SET_CURRENT_PROJECT', item)
          this.getData()
        }
      })
    },
    // 取消
    cancelEdit() {
      this.crud.cancelCU()
      this.getData()
    },
    // 点击高级搜索
    handleCreate() {
      this.crud.resetQuery()
    },
    // 是否查看
    isView() {
      if (this.pageType === 'view') {
        return true
      } else {
        return false
      }
    },
    // 格式化启动状态
    formatStartStatus(rowData1, rowData2) {
      let x = null
      if (!form.hasOwnProperty('startStatus') || !(rowData1 === 2)) {
        if (!form.hasOwnProperty('startStatus') || (rowData1 === 0)) {
          x = '未启动'
        }
        if (rowData1 === 2) {
          x = '启动成功'
        }
        if (rowData1 === -1) {
          x = '启动失败'
        }
        if (rowData1 === 1) {
          x = '启动中'
        }
      }
      if (rowData1 === 2) {
        if (rowData2 === 0) {
          x = '未更新'
        }
        if (rowData2 === 2) {
          x = '更新成功'
        }
        if (rowData2 === -1) {
          x = '更新失败'
        }
        if (rowData2 === 1) {
          x = '更新中'
        }
      }
      return x
    },
    // 格式化运行状态
    formatRunStatus(rowData) {
      let x = null
      switch (rowData) {
        case 1:
          x = '进行中'
          break
        case 2:
          x = '暂停'
          break
        case 3:
          x = '完成'
          break
        case 4:
          x = '废除'
          break
        default:
          x = ''
      }
      return x
    },
    // 格式化项目经理
    formatManager(rowData) {
      const managersList = rowData && rowData.length !== 0 ? JSON.parse(rowData) : []
      if (this.form.managers && this.form.managers.length > 0 && managersList.length > 0) {
        let managers = ''
        this.form.managers.forEach(data => {
          managersList.forEach(item => {
            if (data.user_id === item.user_id && item.enabled === 1) {
              if (managers !== '') {
                managers = managers + '，' + data.nickName
              } else {
                managers = data.nickName
              }
            }
          })
        })
        return managers
      }
    },
    // 格式化设计软件
    formatDesignSoftware(rowData) {
      const designSoftwareList = rowData && rowData.length !== 0 ? JSON.parse(rowData) : []
      if (designSoftwareList.length > 0) {
        let designSoftware = ''
        designSoftwareList.forEach(item => {
          if (designSoftware !== '') {
            designSoftware = designSoftware + '，' + this.dict.label.software[item.id]
          } else {
            designSoftware = this.dict.label.software[item.id]
          }
        })
        return designSoftware
      }
    },
    // 查看
    hanleView(projId) {
      this.crud.data.map((item, index) => {
        if (item.projId === projId) {
          this.crud.toView(this.crud.data[index], 'view')
        }
      })
    },
    deleteSoftWare(value) {
      designSoftware.forEach(function(data, index) {
        if (data.id === value) {
          designSoftware.splice(index, value)
        }
      })
    },
    changeSoftWare(value) {
      designSoftware = []
      value.forEach(function(data) {
        const softWare = { id: data }
        designSoftware.push(softWare)
      })
    },
    // 判断测试版和正式版
    getVersion() {
      // 测试版
      if (process.env.VUE_APP_APP_ID === 'com.haisum.eim.test' || process.env.VUE_APP_APP_ID === 'com.haisum.eim.dev') {
        this.version = 'test'
      } else if (process.env.VUE_APP_APP_ID === 'com.haisum.eim') {
        // 正式版
        this.version = 'prod'
      }
    },
    // 启动项目
    start(id) {
      if (!this.form.area && !this.form.capacity) {
        this.$message({
          message: '请点击修改填写地区和产能！',
          type: 'warning'
        })
      } else if (!this.form.capacity) {
        this.$message({
          message: '请点击修改填写产能！',
          type: 'warning'
        })
      } else if (!this.form.area) {
        this.$message({
          message: '请点击修改填写地区！',
          type: 'warning'
        })
      } else {
        const params = {
          id: id
        }
        const api = start(params)
        api.then(() => {
          this.crud.notify('项目发起启动成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
          this.form.startStatus = 1
          this.$refs[id].doClose()
        }).catch(() => {
          this.$refs[id].doClose()
        })
      }
    },
    // 更新启动项目
    update(id) {
      const params = {
        projId: id
      }
      const api = doUpdateStatus(params)
      api.then(object => {
        this.crud.notify('项目发起更新成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
        this.form.updateStatus = 1
      })
      if (this.$refs[id]) {
        this.$refs[id].doClose()
      }
    },
    // 委托单位
    getUnitDepts() {
      // isExterna true外部 false内部
      getDepts({ enabled: true }).then(res => {
        this.constructionUnits = res.content.map(function(obj) {
          if (obj.hasChildren) {
            obj.children = null
          }
          return obj
        })
      })
    },
    // 主承接
    getDepts() {
      getDepts({ enabled: true, isExternal: false }).then(res => {
        this.depts = res.content.map(function(obj) {
          if (obj.hasChildren) {
            obj.children = null
          }
          return obj
        })
      })
    },
    // 配合公司
    getAssist() {
      getDepts({ enabled: true }).then(res => {
        this.assistCompanys = res.content.map(function(obj) {
          if (obj.hasChildren) {
            obj.children = null
          }
          return obj
        })
      })
    },
    // 委托单位 配合公司 有外部公司
    getSupDepts(deptId, flag) {
      if (deptId) {
        getDeptSuperior(deptId).then(res => {
          const date = res.content
          this.buildDepts(date)
          if (flag === '1') {
            this.constructionUnits = date
          }
          /* 配合公司*/
          if (flag === '2') {
            let a = []
            if (this.form.assistCompany) {
              a = JSON.parse(this.form.assistCompany)
            }
            if (date) {
              this.assistCompanys = this.constructionUnits
              date.map(member => {
                if (member.children) {
                  member.children.map(item => {
                    a.forEach(item2 => {
                      if (item.id === item2) {
                        item.isDisabled = true
                      }
                    })
                  })
                } else {
                  a.forEach(item2 => {
                    if (member.id === item2) {
                      member.isDisabled = true
                    }
                  })
                }
                this.assistCompanys = date
              })
            }
          }
        })
      }
    },
    // 主承接 无外部公司
    getSelfSupDepts(deptId) {
      if (deptId && deptId !== '[]') {
        getDeptSuperiorSelf(deptId).then(res => {
          const date = res.content
          this.buildDepts(date)
          this.depts = date
        })
      }
    },
    buildDepts(depts) {
      depts.forEach(data => {
        if (data.children) {
          this.buildDepts(data.children)
        }
        if (data.hasChildren && !data.children) {
          data.children = null
        }
      })
    },
    // 获取弹窗内部门数据 委托单位
    loadConstructionUnits({ action, parentNode, callback }) {
      if (action === LOAD_CHILDREN_OPTIONS) {
        getDepts({ enabled: true, pid: parentNode.id }).then(res => {
          parentNode.children = res.content.map(function(obj) {
            if (obj.hasChildren) {
              obj.children = null
            }
            return obj
          })
          setTimeout(() => {
            callback()
          }, 200)
        })
      }
    },
    // 获取弹窗内部门数据 主承接
    loadDepts({ action, parentNode, callback }) {
      if (action === LOAD_CHILDREN_OPTIONS) {
        getDepts({ enabled: true, pid: parentNode.id, isExternal: false }).then(res => {
          parentNode.children = res.content.map(function(obj) {
            if (obj.hasChildren) {
              obj.children = null
            }
            return obj
          })
          setTimeout(() => {
            callback()
          }, 200)
        })
      }
    },
    // 获取弹窗内部门数据 配合公司
    assistLoadDepts({ action, parentNode, callback }) {
      const that = this
      if (action === LOAD_CHILDREN_OPTIONS) {
        getDepts({ enabled: true, pid: parentNode.id }).then(res => {
          parentNode.children = res.content.map(function(obj) {
            // 配合公司编辑页新增过的不允许去掉
            if (that.form.assistCompany) {
              let a = []
              a = JSON.parse(that.form.assistCompany)
              if (that.crud.form.projId) {
                a.forEach(item2 => {
                  if (obj.id === item2) {
                    obj.isDisabled = true
                  }
                })
              } else {
                obj.isDisabled = false
              }
            }
            if (obj.hasChildren) {
              obj.children = null
            }
            return obj
          })
          setTimeout(() => {
            callback()
          }, 200)
        })
      }
    },
    // 获取子项启动项目数
    startNumuber(projId) {
      let startNum = 0
      this.crud.data.map(i => {
        if (i.projectSubs && projId === i.projId) {
          i.projectSubs.map(item => {
            if (item.startStatus && item.startStatus === 2) {
              startNum++
            }
          })
        }
      })
      return startNum
    },
    // 主承接改变
    addSelect(value) {
      const deptName = value.label
      const template_file = []
      this.dict.Template_file.map(item => {
        if (deptName === '股份总部') {
          template_file.push({
            label: item.label,
            value: item.value
          })
        } else if (deptName === '广州公司') {
          if (item.value === 'EIM' || item.value === 'GDE') {
            template_file.push({
              label: item.label,
              value: item.value
            })
          }
        } else if (deptName === '长沙公司') {
          if (item.value === 'EIM' || item.value === 'CEC') {
            template_file.push({
              label: item.label,
              value: item.value
            })
          }
        } else {
          if (item.value === 'EIM') {
            template_file.push({
              label: item.label,
              value: item.value
            })
          }
        }
      })
      // 数组对象去重
      const map = new Map()
      this.template_file = template_file.filter(v => !map.has(v.value) && map.set(v.value, 1))
      if (this.form.projId == null) {
        this.form.template = this.template_file[0].value
      }
    },
    changeManager(value) {
      value.forEach(function(data, index) {
        const obj2 = { user_id: data, enabled: 1 }
        // 判断是否含有这个对象，如果有就替换，没有就push
        if (userManagers.length > 0 && userManagers.findIndex((val) => val.user_id === obj2.user_id) !== -1) {
          const index = userManagers.findIndex((val) => val.user_id === obj2.user_id)
          userManagers.splice(index, 1, obj2)
        } else {
          userManagers.push(obj2)
        }
      })
    },
    deleteTag(value) {
      userManagers.forEach(function(data, index) {
        if (data.user_id === value) {
          userManagers.splice(index, value)
        }
      })
    },
    /* 文件格式*/
    acceptFile(e) {
      const allowHook = {
        video: '.mp4, .ogv, .ogg, .webm',
        audio: '.wav, .mp3, .ogg, .acc, .webm, .amr',
        file: 'doc,.docx,.xlsx,.xls,.pdf',
        excel: 'xlsx,.xls',
        img: '.jpg, .jpeg, .png, .gif'
      }
      if (e) {
        return allowHook[e]
      }
      let srt = null
      for (const k in allowHook) {
        srt += allowHook[k]
      }
      return srt
    },
    /* 开始上传前验证*/
    beforeUploadForm(file) {
      /* 验证文件类型*/
      if (file.name) {
        var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
        const extension = testmsg === 'png' || testmsg === 'jpg' || testmsg === 'jpeg' || testmsg === 'gif'
        if (!extension) {
          this.$message.error('上传格式错误')
        }
        return extension
      }
      /* 验证文件大小*/
      if (file.size / 1024 / 1024 > this.formMaxSize) {
        this.$message({
          message: '文件大小不能超过' + this.formMaxSize + 'M！',
          type: 'warning'
        })
        return false
      }
    },
    /* 图片上传超过数量限制*/
    formHandleExceed() {
      this.$message.error('上传图片不能超过' + this.limit + '张!')
    },
    /* 上传图片*/
    uploadError(err, file, fileList) {
      this.$message.error(err)
    },
    // 选择上传列表中文件
    formHandleChange(file, fileList) {
      const existFile = fileList.slice(0, fileList.length - 1).find(f => f.name === file.name)
      if (existFile) {
        this.$message.error('当前文件已经存在!')
        fileList.pop()
      }
      this.fileList = fileList
    },
    // 移除上传列表中文件
    formHandleRemove(file, fileList) {
      this.fileList = fileList
    },
    // 上传文件
    uploadFile(param) {
      this.uploadFormData = new FormData()
      if (param) {
        this.uploadFormData.append('file', param.file)
      }
      if (this.form.projId) {
        this.uploadFormData.append('projId', this.form.projId)
      }
      if (this.form.useTo) {
        this.uploadFormData.append('useTo', this.form.useTo)
      }
      if (this.form.code) {
        this.uploadFormData.append('code', this.form.code)
      }
      if (this.form.name) {
        this.uploadFormData.append('name', this.form.name)
      }
      this.uploadFormData.append('type', this.form.type)
      if (userManagers.length > 0) {
        this.uploadFormData.append('manager', JSON.stringify(userManagers))
      }
      if (this.form.introductory) {
        this.uploadFormData.append('introductory', this.form.introductory)
      }
      if (this.form.area) {
        this.uploadFormData.append('area', this.form.area)
      }
      if (this.form.address) {
        this.uploadFormData.append('address', this.form.address)
      }
      if (this.form.comosStatus) {
        this.uploadFormData.append('comosStatus', this.form.comosStatus)
      }
      if (this.form.comosManager) {
        this.uploadFormData.append('comosManager', this.form.comosManager)
      }
      if (this.assistCompanyIds.length > 0) {
        this.uploadFormData.append('assistCompany', JSON.stringify(this.assistCompanyIds))
      }
      if (this.form.constructionUnitId) {
        this.uploadFormData.append('constructionUnitId', this.form.constructionUnitId)
      }
      if (this.form.industry) {
        this.uploadFormData.append('industry', this.form.industry)
      }
      if (this.form.overallFloorage) {
        this.uploadFormData.append('overallFloorage', this.form.overallFloorage)
      }
      if (this.form.buildingHeight) {
        this.uploadFormData.append('buildingHeight', this.form.buildingHeight)
      }
      if (this.form.buildingHeight) {
        this.uploadFormData.append('buildingHeight', this.form.buildingHeight)
      }
      if (designSoftware.length > 0) {
        this.uploadFormData.append('designSoftware', JSON.stringify(designSoftware))
      }
      if (this.form.template) {
        this.uploadFormData.append('template', this.form.template)
      }
      this.uploadFormData.append('isForeign', this.form.isForeign)
      if (this.form.runStatus) {
        this.uploadFormData.append('runStatus', this.form.runStatus)
      }
      if (this.form.stage) {
        this.uploadFormData.append('stage', this.form.stage)
      }
      if (this.form.capacity) {
        this.uploadFormData.append('capacity', this.form.capacity)
      }
      if (this.form.deptId) {
        this.uploadFormData.append('deptId', this.form.deptId)
      }
      if (this.form.contractCode) {
        this.uploadFormData.append('contractCode', this.form.contractCode)
      }
      if (this.form.constructionCode) {
        this.uploadFormData.append('constructionCode', this.form.constructionCode)
      }
    },
    // 转成字符串
    convertString(val) {
      let value = ''
      if (!val) {
        value = null
      } else {
        value = val
      }
      return value
    },
    // 保存文件
    save() {
      if (this.fileList.length > 0) {
        this.$refs.upload.submit()
        this.crud.submitCU2(this.uploadFormData)
      } else {
        this.uploadFile()
        this.crud.submitCU2(this.uploadFormData)
      }
    },
    // 格式化图片地址
    formatImage(form) {
      let urlF = ''
      if (form.image) {
        urlF = this.baseApi + '/api/project/showProjImage' + '?projId=' + form.projId
      }
      return urlF
    },
    // 同步
    synchronousAllProjInfo() {
      if (this.form.code) {
        this.$confirm(`确认同步数据?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          const params = {
            projectCode: this.form.code
          }
          fetchAndSyncAllProjInfo(params).then(object => {
            this.crud.notify('同步成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
            this.crud.query.projCode = object.code
            this.crud.refresh()
          })
        }).catch(() => {
        })
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  ::v-deep .vue-treeselect__single-value {
    color: #333;
  }
  .form-title{
    width: 100%;
    height: 46px;
    font-weight: 600;
    font-size: 15px;
    color: var(--brother-common-tips-text-color);
    padding-left: 18px;
  }
  /*.el-form--inline {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: 10px;
  }
  .el-form--inline .el-form-item {
    flex: 0 0 auto;
    margin-right: 10px;
    box-sizing: border-box;
    width: calc(33.333% - 10px);
  }*/

  /*  @media (min-width: 2560px) and (min-height: 1440px) {
      .info-main {
        width: 80%;
      }
    }
    @media (min-width: 1920px) and (max-width: 1919px) and (min-height: 1080px) {
      .info-main {
        width: 117%;
      }
    }

    @media (max-width: 1919px) {
      .info-main {
        width: 101%;
      }
    }*/
  .avatar {
    width: 180px;
    height: 180px;
  }
  .text-width{
    width:360px;
  }
  .text-width2{
    width: 200px;
  }
  .text-width4{
    width: 340px;
  }
  .projectInfo-info {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .projectInfo-info li {
    flex: 0 0 29.333%;
    padding: 9px;
    position: relative;
    font-size: 14px;
    color: var(--brother-common-table-empty-text-color);
    margin-left: 61px;
    margin-bottom: 9px;
    font-weight: 600;
  }

  .projectInfo-info li > div:first-of-type {
    position: absolute;
    right: -131px;
    top: 10px;
    width: calc(100% - 20px);
    text-align: left;
    font-weight: normal;
  }
  .upload-demo{
    float: left;
    margin-left: 13px;
  }
  ::v-deep .star>.el-form-item__label:before{
    content: "*";
    color: #ff4949;
    margin-right: 4px;
  }
  ::v-deep .el-upload-dragger {
    width: 370px;
    height: 190px;
    border:none;
  }
  ::v-deep .el-upload--picture-card{
    width: 100%;
    height: 100%;
  }
</style>
<style type="text/css" lang="scss">
  .info-row{
    padding-left: 60px !important;
    box-sizing: border-box;
    width: 100%;
    .el-col{
      padding: 10px;
      position: relative;
      font-size: 14px;
      color: var(--brother-common-table-empty-text-color);
      // margin-left: 61px;
      margin-bottom: 8px;
      font-weight: 600;
    }

    .el-col > div:first-of-type {
      position: absolute;
      right: 0;
      top: 10px;
      width: calc(100% - 150px);
      text-align: left;
      font-weight: normal;
    }
  }
</style>
